package com.neusoft.elmboot.controller;

import com.neusoft.elmboot.po.dto.UserPointTupleDTO;
import com.neusoft.elmboot.po.point.Point;
import com.neusoft.elmboot.service.PointService;
import com.neusoft.elmboot.service.PointTransactionService;
import com.neusoft.elmboot.util.response.ResultBody;
import jakarta.annotation.Resource;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/point")
public class PointController {

    @Resource
    private PointService pointService;

    @Resource
    private PointTransactionService pointTransactionService;

    @PostMapping("/init")
    public ResultBody initPoint(@RequestParam String userId,
                                @RequestParam(required = false) Integer value){
        pointService.init(userId, value);
        return ResultBody.success();
    }

    @PostMapping("/addPoint")
    public ResultBody addPoint(@RequestParam String userId,
                               @RequestParam Integer channelId,
                               @RequestParam(required = false) String eventId,
                               @RequestParam Integer amount) {
        pointService.addPoint(userId, channelId, eventId, amount);
        return ResultBody.success();
    }

    @PostMapping("/exchange")
    public ResultBody exchange(@RequestBody List<UserPointTupleDTO> tupleList){
        pointService.exchange(tupleList);
        return ResultBody.success();
    }

    @GetMapping("/getPointMallList")
    public ResultBody getPointMallList(){
        return ResultBody.success(pointService.getPointMallList());
    }

    @GetMapping("/showUserPointTupleList")
    public ResultBody showUserPointTupleList(String userId){
        return ResultBody.success(pointService.showUserPointTupleList(userId));
    }

    @GetMapping("/getPointTrans")
    public ResultBody getPointTrans(String userId, Integer index){
        return ResultBody.success(pointTransactionService.getPointTrans(userId, index));
    }

}
